/**
 * 管理初始化
 */
 var SdcBasePlanItem = {
    id: "SdcBasePlanItemTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
SdcBasePlanItem.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
        {title: '代码', field: 'code', align: 'center', valign: 'middle', sortable: true},
        {title: '类型', field: 'type', align: 'center', valign: 'middle', sortable: true},
        {title: '描述', field: 'content', align: 'center', valign: 'middle', sortable: true},
        {title: '参数', field: 'param', align: 'center', valign: 'middle', sortable: true}
    ];
};

/**
 * 检查是否选中
 */
SdcBasePlanItem.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Sys.info("请先选中表格中的某一记录！");
        return false;
    }else{
        SdcBasePlanItem.seItem = selected[0];
        return true;
    }
};
SdcBasePlanItem.setPlanId = function(layero, index, iframeWin){
    iframeWin.SdcBasePlanItemInfoDlg.setPlanId(SdcBasePlan.selectedPlan.id);
}
/**
 * 点击新增
 */
SdcBasePlanItem.add = function () {
    if(!SdcBasePlan.selectedPlan.id){
        Sys.info("请先选择一条方案记录！");
        return false;
    }
    var index = Sys.open('新增',Sys.backendPath + '/sdc/sdcbaseplanitem/to_add',['800px', '420px'],SdcBasePlanItem.setPlanId);
    this.layerIndex = index;
};

/**
 * 打开查看详情
 */
SdcBasePlanItem.edit = function (id) {
	var flag = false;
	if(id){
		flag = true;
	}else if (this.check()) {
        id = this.seItem.id;
        flag = true;
    }
	if (flag) {
    	var index = Sys.open('详情',Sys.backendPath + '/sdc/sdcbaseplanitem/to_update/' + id,['800px', '420px']);
        this.layerIndex = index;
    }
};

/**
 * 删除
 */
SdcBasePlanItem.del = function (id,name) {
	var flag = false;
	if(id){
		flag = true;
	}else if (this.check()) {
        id = this.seItem.id;
        name = this.seItem.name
        flag = true;
    }
	if (flag) {
        var operation = function(){
	        var ajax = new $ax(Sys.backendPath + "/sdc/sdcbaseplanitem/delete", function (data) {
	            Sys.success("删除成功!");
	            SdcBasePlanItem.table.refresh();
	        }, function (data) {
	            Sys.error("删除失败!" + data.responseJSON.message + "!");
	        });
	        ajax.set("sdcBasePlanItemId",id);
	        ajax.start();
	    };
	    Sys.confirm("是否删除?",operation);
    }
};

$(function () {
    var defaultColunms = SdcBasePlanItem.initColumn();
    var table = new BSTable(SdcBasePlanItem.id, Sys.backendPath + "/sdc/sdcbaseplanitem/list", defaultColunms);
    table.setPaginationType("server");
    table.setPageSize(5);
    table.setShowRefresh(false);
    table.setShowColumns(false);
    table.setShowToggle(false);
    table.setShowExport(false);
    table.setQueryParams({ NotQuery: true });
    SdcBasePlanItem.table = table.init();
});
